#!/usr/bin/python3
# -*- coding: utf-8 -*-
'''
# @file   : Cartesian.py
# @author : weichy
# @date   : 2018/12/22
# @version: 1.0
# @desc   :  利用递归设置分形树
'''
# from turtle import *
import turtle


def draw_branch(branch_length):
    # 绘制分形树函数

    # 先绘制右侧树枝
    if branch_length > 5:
        if branch_length < 20:
             turtle.color('green')
        else:
             turtle.color('red')
        turtle.forward(branch_length)
        print('向前',branch_length)
        turtle.right(20)
        print('右转20')
        draw_branch(branch_length-15)

        # 绘制左侧树枝
        turtle.left(40)
        draw_branch(branch_length - 15)

        if branch_length < 20:
            turtle.color('green')

        else:
            turtle.color('red')
        # 返回之前的树枝上
        turtle.right(20)
        turtle.backward(branch_length)


def main():

#     turtle.up()
#     turtle.backward(200)
#     turtle.down()
#     turtle.speed(0.5)
#     turtle.pensize(5)
#     turtle.color("black", "yellow")
#     turtle.begin_fill()
    turtle.left(90)
    turtle.penup()
    turtle.backward(150)
    turtle.pendown()
    turtle.color('blue')
    size = 85
    draw_branch(size)
    # while size <=100:
    #     # draw_pentagram(size)

    #     size += 20
    # turtle.end_fill()
    # turtle.begin_fill()
    # for i in range(5):
    #     turtle.forward(200)
    #     turtle.right(144)
    turtle.done()


if __name__ == '__main__':
    main()
